package com.eagle.client;

import com.google.gwt.core.client.EntryPoint;
import com.gwtext.client.core.EventObject;
import com.gwtext.client.core.Ext;
import com.gwtext.client.core.Margins;
import com.gwtext.client.core.Position;
import com.gwtext.client.core.RegionPosition;
import com.gwtext.client.widgets.Button;
import com.gwtext.client.widgets.Panel;
import com.gwtext.client.widgets.QuickTipsConfig;
import com.gwtext.client.widgets.TabPanel;
import com.gwtext.client.widgets.Toolbar;
import com.gwtext.client.widgets.ToolbarButton;
import com.gwtext.client.widgets.ToolbarTextItem;
import com.gwtext.client.widgets.Viewport;
import com.gwtext.client.widgets.Window;
import com.gwtext.client.widgets.event.ButtonListenerAdapter;
import com.gwtext.client.widgets.form.ComboBox;
import com.gwtext.client.widgets.form.Field;
import com.gwtext.client.widgets.form.FormPanel;
import com.gwtext.client.widgets.form.TextField;
import com.gwtext.client.widgets.layout.BorderLayout;
import com.gwtext.client.widgets.layout.BorderLayoutData;
import com.gwtext.client.widgets.layout.FitLayout;

public class DemoControlPanel3 implements EntryPoint
{
    private TabPanel centerPanel;

    public void onModuleLoad()
    {
	Panel mainPanel = new Panel();
	mainPanel.setLayout(new BorderLayout());

	BorderLayoutData northLayoutData = new BorderLayoutData(RegionPosition.NORTH);
	northLayoutData.setSplit(false);

	BorderLayoutData centerLayoutData = new BorderLayoutData(RegionPosition.CENTER);
	centerLayoutData.setMargins(new Margins(5, 0, 5, 5));

	Panel centerPanelWrappper = new Panel();
	centerPanelWrappper.setLayout(new FitLayout());
	centerPanelWrappper.setBorder(false);
	centerPanelWrappper.setBodyBorder(false);

	centerPanel = new TabPanel();
	centerPanel.setBodyBorder(false);
	centerPanel.setEnableTabScroll(true);
	centerPanel.setAutoScroll(true);
	centerPanel.setAutoDestroy(false);
	centerPanel.setActiveTab(0);


	centerPanel.setLayoutOnTabChange(true);
	centerPanel.setTitle("Main Content");

	// screenManager = new ScreenManager(centerPanel);

	// setup the west regions layout properties
	BorderLayoutData westLayoutData = new BorderLayoutData(RegionPosition.WEST);
	westLayoutData.setMargins(new Margins(5, 5, 0, 5));
	westLayoutData.setCMargins(new Margins(5, 5, 5, 5));
	westLayoutData.setMinSize(155);
	westLayoutData.setMaxSize(350);
	westLayoutData.setSplit(true);

	BorderLayoutData eastLayoutData = new BorderLayoutData(RegionPosition.EAST);
	eastLayoutData.setMargins(new Margins(5, 5, 0, 5));
	eastLayoutData.setCMargins(new Margins(5, 5, 5, 5));
	eastLayoutData.setMinSize(155);
	eastLayoutData.setMaxSize(350);
	eastLayoutData.setSplit(true);

	// create the west panel and add it to the main panel applying the west
	// region layout properties
	Panel westPanel = createWestPanel();
//	mainPanel.add(westPanel, westLayoutData);


	final Panel panelA = new Panel();
	panelA.setTitle("panelA");
	panelA.setPaddings(10);
	panelA.setLayout(new FitLayout());
	// final ShowcaseView showcaseView = new ShowcaseView(screenManager);
	// introPanel.add(showcaseView);
	
	final Panel panelB = new Panel();
	panelB.setTitle("panelB");
	panelB.setPaddings(10);
	panelB.setLayout(new FitLayout());

	
	Field field = new TextField("panelB field");
	field.hide();
	
	ComboBox cb = new ComboBox("sss");
	cb.hide();
	
	FormPanel formPanel = new FormPanel();
	formPanel.add(field);
//	formPanel.add(cb);
	panelB.add(formPanel);
	
	centerPanel.add(panelA);
	centerPanel.add(panelB);
	
//	Toolbar toolbar = new Toolbar();
//	panelB.add(toolbar);
//	toolbar.setVisible(false);
	
	centerPanelWrappper.add(centerPanel);
	mainPanel.add(centerPanelWrappper, centerLayoutData);

	Viewport viewport = new Viewport(mainPanel);

    }


    private Panel createWestPanel()
    {
	Panel westPanel = new Panel();
	westPanel.setId("side-nav");
	westPanel.setTitle("Showcase Explorer");
	westPanel.setLayout(new FitLayout());
	westPanel.setWidth(210);
	westPanel.setCollapsible(true);

	Toolbar toolbar = new Toolbar();

	if (Ext.isFirebug())
	{
	    ToolbarButton button = new ToolbarButton();
	    button.setIconCls("bug-icon");
	    QuickTipsConfig qtipsConfig = new QuickTipsConfig();
	    qtipsConfig.setText("Firebug can make the demo run slow.");
	    qtipsConfig.setWidth(100);
	    qtipsConfig.setMaxWidth(100);
	    button.setTooltip(qtipsConfig);
	    button.addListener(new ButtonListenerAdapter()
	    {
		public void onClick(Button button, EventObject e)
		{
		    Panel fb = new Panel();
		    fb.setAutoScroll(true);
		    fb.setAutoLoad("firebug.html");
		    final Window window = new Window("Firebug");
		    window.setIconCls("bug-icon");
		    window.setWidth(550);
		    window.setHeight(260);
		    window.add(fb);
		    window.setCloseAction(Window.CLOSE);
		    window.show(button.getElement());

		}
	    });
	    toolbar.addButton(button);
	}
	toolbar.addFill();
	toolbar.addItem(new ToolbarTextItem("Select Theme "));
	toolbar.addSpacer();
	// toolbar.addField(new ThemeChanger());
//	westPanel.setTopToolbar(toolbar);

	TabPanel tabPanel = new TabPanel();
	tabPanel.setActiveTab(0);
	tabPanel.setDeferredRender(true);
	tabPanel.setTabPosition(Position.BOTTOM);
	 tabPanel.setTitle("tabPanel");
	// TreePanel treePanel = screenManager.getTreeNav();


	westPanel.add(tabPanel);

	return westPanel;
    }

}
